package com.test.dababy.dababy_01_launcher;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.webkit.WebView;

import com.test.dababy.dababy_00_analytics.dababydata_sdk.DababyASBuilder;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.DababyASSycManager;
import com.test.dababy.dababy_00_utils.DababyUtil;

import org.jetbrains.annotations.NotNull;


public class Base_dababyApplication extends Application {

    private double prmH=0.49856385982719365;
    private String he2F="";
    private double c5qc=0.027628474374546852;
    private boolean u7ob=true;
    private boolean qg6N=false;
    private boolean aIjb=false;
    private char pEkr='l';
    private double w1O1=0.6502839834959441;
    private char dH3h='d';
    private boolean h2X3=true;
    private String u42R="";
    private String kDSX="";

    public void p4l8v(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getHe2F()))
                    setU42R(String.valueOf(getPrmH())+getC5qc()+isU7ob()+isQg6N()+isaIjb());
                else setkDSX(String.valueOf(getpEkr())+getW1O1()+getdH3h()+isH2X3());

            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setPrmH(double prmH) {
        this.prmH = prmH;
    }

    public void setHe2F(String he2F) {
        this.he2F = he2F;
    }

    public void setC5qc(double c5qc) {
        this.c5qc = c5qc;
    }

    public void setU7ob(boolean u7ob) {
        this.u7ob = u7ob;
    }

    public void setQg6N(boolean qg6N) {
        this.qg6N = qg6N;
    }

    public void setaIjb(boolean aIjb) {
        this.aIjb = aIjb;
    }

    public void setpEkr(char pEkr) {
        this.pEkr = pEkr;
    }

    public void setW1O1(double w1O1) {
        this.w1O1 = w1O1;
    }

    public void setdH3h(char dH3h) {
        this.dH3h = dH3h;
    }

    public void setH2X3(boolean h2X3) {
        this.h2X3 = h2X3;
    }

    public void setU42R(String u42R) {
        this.u42R = u42R;
    }

    public void setkDSX(String kDSX) {
        this.kDSX = kDSX;
    }

    public double getPrmH() {
        return prmH;
    }

    public String getHe2F() {
        return he2F;
    }

    public double getC5qc() {
        return c5qc;
    }

    public boolean isU7ob() {
        return u7ob;
    }

    public boolean isQg6N() {
        return qg6N;
    }

    public boolean isaIjb() {
        return aIjb;
    }

    public char getpEkr() {
        return pEkr;
    }

    public double getW1O1() {
        return w1O1;
    }

    public char getdH3h() {
        return dH3h;
    }

    public boolean isH2X3() {
        return h2X3;
    }

    public String getU42R() {
        return u42R;
    }

    public String getkDSX() {
        return kDSX;
    }

    private static Base_dababyApplication Base_dababyApp_dababylication;

    private String ms_dababyg;;

    @NotNull
    public static Base_dababyApplication getInstant() {
        return Base_dababyApp_dababylication;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Base_dababyApp_dababylication = this;
        try {
            //pie webview 适配
            initP_dababyieW_dababyebView();
            //user info
            DababyUtil.dababyInit(getApplicationContext());

            //syc data sdk
            init_dababySyc_dababyData_dababySDK();

        } catch (Exception e) {
            e.printStackTrace();
            p4l8v();
        }
    }

    /**
     * 适配android 9 网络进程
     */
    private void initP_dababyieW_dababyebView() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            String processName = getPro_dababycessName(this);
            if (!DababyUtil.getPackageName_dababy().equals(processName)) {
                WebView.setDataDirectorySuffix(processName);
            }
        }
    }

    private String getPro_dababycessName(Context context) {
        if (context == null) return null;
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (manager != null) {
            for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
                if (processInfo.pid == android.os.Process.myPid()) {
                    return processInfo.processName;
                }
            }
        }
        return "";
    }

    public void init_dababySyc_dababyData_dababySDK() {
        try {
            // 初始化
            DababyASSycManager.getInstance_dababy().init_dababy(this);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setMs_dababyg(String ms_dababyg) {
        this.ms_dababyg = ms_dababyg;
    }

    public String getMs_dababyg() {
        if (ms_dababyg == null) return "";
        final String fMSg = ms_dababyg;
        ms_dababyg = "";
        return fMSg;
    }

}
